#ifndef __USER_SID31_SERVICE_H__
#define __USER_SID31_SERVICE_H__

#include <stdint.h>

#define ROUTINE_CTRL_RECORD_DATA_LEN    0x0A
#define ROUTINE_RESULT_RECORD_DATA_LEN	0x0A

#define ROUTINE_CTRL_REQ_ERASE_MEM_MESSAGE_LEN          0x0D
#define ROUTINE_CTRL_REQ_ERASE_MEM_RESULT_LEN           0x04
#define ROUTINE_CTRL_RESP_ERASE_MEM_RESULT_LEN          0x04
#define ROUTINE_CTRL_POSTV_RESP_START_MESSAGE_LEN		0x06
#define	ROUTINE_CTRL_POSTV_RESP_REQ_RESULT_MESSAGE_LEN	0x04

/*routine control subfunction*/
typedef enum
{
	START_ROUTINE			= 0x01,
	STOP_ROUTINE			= 0x02,
	REQ_ROUTINE_RESULT		= 0x03, 
}routine_ctrl_sub_enum;


/*routine type*/
typedef enum
{
	ERASE_MEM				= 0xDFFF,
	CHECK_MEM				= 0xDFFE,
	SLAVE_NODE_MODE_SELE	= 0xDFF0, 
}rid_enum;

/*routine control request*/
#pragma pack(1)
typedef struct
{
    uint8_t sid;                                                    //例程控制服务
    routine_ctrl_sub_enum subfunction;                              //例程控制子服务类型
    rid_enum rid;                                                   //例程控制ID标识符
    uint8_t routine_ctrl_record_data[ROUTINE_CTRL_RECORD_DATA_LEN]; //例程控制可选参数
}routine_ctrl_req_struct;
#pragma pack()


/*routine control positive respond*/
#pragma pack(1)
typedef struct
{
	uint8_t positive_resp_id;                                           //例程控制积极响应服务
	routine_ctrl_sub_enum subfunction;                                  //例程控制子服务类型
	rid_enum rid;                                                       //例程控制ID标识符
	uint8_t routine_result_record_data[ROUTINE_RESULT_RECORD_DATA_LEN]; //例程控制回复结果参数
}routine_ctrl_positive_resp_struct;
#pragma pack()


/*routine control record:erase memory*/
#pragma pack(1)
typedef struct 
{
	uint8_t mem_add_and_size_byte_len;/*default:0x44*/                  //内存起始地址长度和内存大小长度
	uint32_t mem_start_add;                                             //内存起始地址
	uint32_t mem_size;                                                  //内存大小
}routine_ctrl_record_erase_mem_struct;
#pragma pack()


/*routine control record:check memory*/
#pragma pack(1)
typedef struct 
{
    uint8_t sid;
    routine_ctrl_sub_enum subfunction;
    rid_enum rid;
	uint32_t check_value;
}routine_ctrl_record_check_mem_struct;
#pragma pack()



typedef struct
{
    routine_ctrl_sub_enum sub_func;                         //子功能(例程控制子服务类型)
    rid_enum rid;                                           //rid(例程控制ID标识符)
    uint8_t req_len;                                        //请求报文长度
    uint8_t resp_len;                                       //响应报文长度
    int16_t (*handle_cb)(uint8_t*,uint8_t*);                //回调处理函数指针
}routine_control_str;




int16_t Routine_Control_Port(uint8_t *rec_buf, uint8_t *rsp_buf, uint16_t rec_len);

#endif